package com.nianzhen.recruitment;

import com.nianzhen.utils.AsyncAPI;
import com.nianzhen.utils.ToastBreak;
import com.nianzhen.weight.SlideSwitch;
import com.nianzhen.weight.SlideSwitch.SlideListener;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LoginActivity extends BaseFragmentActivity implements
		OnClickListener {

	private SlideSwitch iSwitch;
	private EditText mUserEt;
	private EditText mPassword;
	private TextView mForgetPsdTv;
	private TextView mReTv;
	private Button mSubTn;

	private boolean who;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);
		iSwitch = (SlideSwitch) findViewById(R.id.login_checkbox);
		mUserEt = (EditText) findViewById(R.id.login_user);
		mPassword = (EditText) findViewById(R.id.login_pass);
		mForgetPsdTv = (TextView) findViewById(R.id.login_forget);
		mReTv = (TextView) findViewById(R.id.login_re);
		mSubTn = (Button) findViewById(R.id.login_btn);
		who = true;
		mForgetPsdTv.setOnClickListener(this);
		mReTv.setOnClickListener(this);
		mSubTn.setOnClickListener(this);
		iSwitch.setState(who);
		iSwitch.setSlideListener(new SlideListener() {

			@Override
			public void open() {
				// TODO Auto-generated method stub
				who = true;
			}

			@Override
			public void close() {
				// TODO Auto-generated method stub
				who = false;
			}
		});

	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()) {
		case R.id.login_forget:
			startActivity(new Intent(LoginActivity.this,
					ForgetPsdActivity.class));
			break;
		case R.id.login_re:
			startActivity(new Intent(LoginActivity.this,
					RegisterActivity.class));
			break;
		case R.id.login_btn:
			if (!TextUtils.isEmpty(mUserEt.getText())||!TextUtils.isEmpty(mPassword.getText())) {
				ToastBreak.showToast("用户名或者密码为空");
			}else {
				if (mPassword.getText().toString().length()<6||mPassword.getText().toString().length()>16) {
					ToastBreak.showToast("密码长度小于6位或者大于16位");
				}else {
					doLogin();
				}
			}
			break;
		default:
			break;
		}
	}

	private void doLogin() {
		// TODO Auto-generated method stub
		
		//AsyncAPI.post(url, params, responseHandler);
	}

}
